package com.youhome.service.impl;

import com.youhome.mapper.ClientMapper;
import com.youhome.model.Client;
import com.youhome.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by chen365 on 2018/12/11.
 */
@Service
public class ClientServiceImpl implements ClientService {
    @Autowired
    private ClientMapper clientMapper;

    @Override
    public Client selectByPrimaryKey(Long clientId) {
        return clientMapper.selectByPrimaryKey(clientId);
    }

    @Override
    public Client selectByUserId(Long userId) {
        return clientMapper.selectByUserId(userId);
    }

    @Override
    public int updateByPrimaryKeySelective(Client record) {
        record.setUtime(new Date());
        return clientMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int save(Client client) {
        if (client.getClientId() != null && client.getClientId() > 0) {
            client.setUtime(new Date());
            return clientMapper.updateByPrimaryKeySelective(client);
        }
        client.setCtime(new Date());
        return clientMapper.insertSelective(client);
    }
}
